/*
 * @Descripttion: 大三一名学习前端开发的计科学生，缓慢成长中！
 * @emial: 2392862431@qq.com
 * @Author: SummerSofts
 * @Date: 2023-07-11 17:30:09
 * @LastEditors: SummerSofts 2392862431@qq.com
 * @LastEditTime: 2023-12-29 22:04:38
 */
import axios from "axios";
import Vue from 'vue'
import router from "../router/index";
import {config} from "./params"
let host1 = "http://127.0.0.1:8000";
let host2 = 'http://106.53.99.242:8000'
let $postFile = (url, data) => {
  const token = localStorage.getItem("token");
  return new Promise((resolve, reject) => {
    axios({
      method: "POST",
      url: config.requestUrl + url,
      headers: {
        "Content-Type": "multipart/form-data",
        Authorization: token,
      },
      data,
    })
      .then((res) => {
        if (res.data.status === 402) {
          router.push("/login");
          ElNotification({
            title: "Error",
            offset: 100,
            message: "身份验证失败，请重新登录！",
            type: "error",
          });
        } else resolve(res.data);
      })
      .catch((err) => {
        reject(err);
      });
  });
};

export default {
  install: (app) => {
    Vue.prototype.$postFile = $postFile;
  },
};
